Streaming algorithm